package com.example.work3.Service.Impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.work3.Entity.Bus;
import com.example.work3.Entity.BusVo;
import com.example.work3.Mapper.BusMapper;
import com.example.work3.Service.BusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BusServerImpl implements BusService {
    @Autowired
    private BusMapper busMapper;

    @Override
    public List<Bus> getAllBus() {
        List<Bus> buses = busMapper.selectList(null);
        return buses;
    }

    @Override
    public Bus getBusById(Integer id) {
        return busMapper.selectById(id);
    }

    @Override
    public boolean insertBus(Bus bus) {
        return busMapper.insert(bus)>0?true:false;
    }

    @Override
    public boolean deleteBusById(Integer id) {
        return busMapper.deleteById(id)>0?true:false;
    }

    @Override
    public boolean updateBus(Bus bus) {
        return busMapper.updateById(bus)>0?true:false;
    }

    @Override
    public BusVo queryList(Integer current, Integer size) {
        BusVo busVo = new BusVo();
        IPage<Bus> page = new Page<>(current,size);
        busMapper.selectPage(page,null);
        busVo.setCurrent(current);
        busVo.setSize(size);
        busVo.setTotal(page.getTotal());
        busVo.setBuses(page.getRecords());
        return busVo;
    }
}
